package cn.zktr.Personnel.controllers.tanyali;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.zktr.Personnel.model.pojos.PerEmaAgt;
import cn.zktr.Personnel.model.pojos.PerEmaTm;
import cn.zktr.Personnel.model.service.tanyali.EmaQsbService;

@Controller
public class EmaQsbController {

	@Autowired
	private EmaQsbService qsbervice;
	
	
	@RequestMapping("tyl/ti-ku")
	public void demo1() {}
    	
	/**
	 * @param tt题库查询功能(搜索框内模糊查询)
	 */
	@RequestMapping("tikuchaxun")
	@ResponseBody
	public Map<String,Object> tikuchaxun(String qsbbank,int page,int rows){
		Map<String,Object> map= new HashMap<>();
		map.put("total", qsbervice.tkchaxun(qsbbank).size());
		Page<Object> p=PageHelper.startPage(page,rows);
		JSONArray tkchaxun = qsbervice.tkchaxun(qsbbank);
		map.put("rows", tkchaxun);
		return map;
	}
	

	@RequestMapping("tyl/tk-dan-shun")
	public void demo2() {}

    	
	/**
	 * @param tt题库查询选择题(搜索框内模糊查询)
	 */
	@RequestMapping("tikudanshunchaxun")
	@ResponseBody
	public Map<String,Object> tikudanshunchaxun(String tmsub,int page,int rows){
		Map<String,Object> map= new HashMap<>();
		map.put("total", qsbervice.tkdschaxun(tmsub).size());
		Page<Object> p=PageHelper.startPage(page,rows);
		JSONArray tkdschaxun = new JSONArray();
		for (int i = 0; i < qsbervice.tkdschaxun(tmsub).size(); i++) {
			JSONObject json = new JSONObject();
			json = qsbervice.tkdschaxun(tmsub).getJSONObject(i);
			String[] split = json.get("TMSUB").toString().split("#");
			String tms = split[0];
			json.put("tm", tms);
			for (int j = 1; j < split.length; j++) {
				String DA = split[j];
				json.put("DA"+j, DA);
			}
			tkdschaxun.add(json);
		};
		map.put("rows", tkdschaxun);
		return map;
	}
	
	/**
	 * @param tt选择题库下拉更新
	 */
	@RequestMapping("dstikuxiala")
	@ResponseBody
	public Map<String,Object> tikuxiala(String QSB,int page,int rows){
		Map<String,Object> map= new HashMap<>();
		map.put("total", qsbervice.tkchaxun(QSB).size());
		JSONArray tikuxiala = qsbervice.tikuxiala(QSB);
		map.put("rows", tikuxiala);
		return map;
	}
	
	/**
	 * @param tt综合题库下拉更新
	 */
	@RequestMapping("zhtikuxiala")
	@ResponseBody
	public Map<String,Object> tikuxialas(String QSBS,int page,int rows){
		Map<String,Object> map= new HashMap<>();
		map.put("total", qsbervice.tkchaxun(QSBS).size());
		JSONArray tikuxiala = qsbervice.tikuxialas(QSBS);
		map.put("rows", tikuxiala);
		return map;
	}
	
	/**
	 * @param febid
	 * @param outid
	 * @return 选择题修改调用
	 */
	@PostMapping("xztxiugai")
	@ResponseBody
	public String xztxiugai(Integer tmid,String xxa,String xxb,String xxc,String xxd,String daan,String timu) {
		qsbervice.xztxiugai(tmid, xxa, xxb, xxc, xxd, daan, timu);
		return "";
	}
	
	
	@RequestMapping("tyl/tk-zong-he")
	public void demo3() {}
	
	/**
	 * @param tt题库查询综合题(搜索框内模糊查询)
	 */
	@RequestMapping("tikuzonghechaxun")
	@ResponseBody
	public Map<String,Object> tikuzonghechaxun(String tmsub,int page,int rows){
		Map<String,Object> map= new HashMap<>();
		map.put("total", qsbervice.tkzhchaxun(tmsub).size());
		Page<Object> p=PageHelper.startPage(page,rows);
		JSONArray tkzhchaxun = new JSONArray();
		for (int i = 0; i < qsbervice.tkzhchaxun(tmsub).size(); i++) {
			JSONObject json = new JSONObject();
			json = qsbervice.tkzhchaxun(tmsub).getJSONObject(i);
			String[] split = json.get("TMSUB").toString().split("#");
			String tms = split[0];
			json.put("tm", tms);
			for (int j = 1; j < split.length; j++) {
				String DA = split[j];
				json.put("DA"+j, DA);
			}
			tkzhchaxun.add(json);
		};
		map.put("rows", tkzhchaxun);
		return map;
	}
	
	/**
	 * @param febid
	 * @param outid
	 * @return 综合题修改调用
	 */
	@PostMapping("zhtxiugai")
	@ResponseBody
	public String zhtxiugai(Integer tmid,String daan,String timu) {
		qsbervice.zhtxiugai(tmid,daan, timu);
		return "";
	}
	
	/**
	 * @param febid
	 * @param outid
	 * @return 信息反馈修改调用
	 */
	@PostMapping("xxfkxiugai")
	@ResponseBody
	public String xxfkxiugai(Integer bianhao,String kaikao,String jieshu,String shichang,String didian) {
		qsbervice.xxfkxiugai(bianhao,kaikao,jieshu,shichang,didian);
		return "";
	}
	
	
	/**
	 * 题目删除
	 */
	@PostMapping("deleteDX")
	@ResponseBody
	public String deleteDX(Integer tmzid) {
		System.err.println();
		qsbervice.deleteDX(tmzid);
		return "";
	}
	
}
